//
//  PostModel.m
//  sensen_ios
//
//  Created by pro on 16/3/1.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "PostModel.h"
#import <CoreText/CoreText.h>
@implementation PostModel

- (id)initContentWithDic:(NSDictionary *)jsonDic {
    self = [super init];
    if (self != nil) {
        [self setAttributes:jsonDic];
        _postTitle = jsonDic[@"subject"];
        if ([jsonDic[@"subject"] isKindOfClass:[NSNull class]]) {
            _postTitle = @"";
        }
        _postContent = jsonDic[@"message"];
        id userInfoDic = jsonDic[@"user_info"];
        if (![userInfoDic isKindOfClass:[NSNull class]]) {
            userInfoDic = (NSDictionary *)userInfoDic;
            NSString *head = userInfoDic[@"head"];
        
            if ([head checkPositiveInteger]) {
                _authorImage = [NSString stringWithFormat:@"%@%@",BOYE_PICTURE_URL,head];
            }else{
                _authorImage = head;
            }

            
            
            if (![userInfoDic[@"nickname"] isKindOfClass:[NSNull class]]) {
                _nickname = userInfoDic[@"nickname"];
                if (_nickname.length == 0) {
                    _nickname = _author;
                }
            }else{
                _nickname = _author;
            }
            
            id grDic = userInfoDic[@"group"];
            if (![grDic isKindOfClass:[NSNull class]]) {
                _isAllowpost = grDic[@"allowpost"];
            }
        }
        if (_isAllowpost == nil) {
            _isAllowpost = @"1";
        }
//        _imgAry =jsonDic[@"img"];
//        http://sunsun.itboye.com/index.php/Api/Picture/index?id=此处填写图片id
//        NSString *url = [NSString stringWithFormat:@"%@/File/upload?client_id=%@",BOYE_API_URL, BOYE_CLIENT_ID];
        _imgAry = [[NSMutableArray alloc] init];
        NSArray *tmpArray;
        tmpArray = jsonDic[@"img"];
        if (![jsonDic[@"img"] isKindOfClass:[NSNull class]]){
            for (NSString *url in tmpArray) {
                NSString *str = [NSString stringWithFormat:@"%@%@",BOYE_PICTURE_URL,url];
                [_imgAry addObject:str];
                _firstImg = _imgAry[0];
            }
        }
        
    }    
    return self;
}

@end
